import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

////插件的制作(可以不用每次在Login.vue中导入，例如登录的请求封装)
import {postRequest} from "./tuils/api";
import {postKeyValueRequest} from "./tuils/api";
import {getRequest} from "./tuils/api";
import {putRequest} from "./tuils/api";
import {deleteRequest} from "./tuils/api";
import {initMenu} from "./tuils/menus";
import 'font-awesome/css/font-awesome.min.css'
import axios from "axios";
//赋值引用
Vue.prototype.postRequest = postRequest;
Vue.prototype.postKeyValueRequest = postKeyValueRequest;
Vue.prototype.getRequest = getRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.deleteRequest = deleteRequest;
////

//设置全局前缀（window.open(url)不会加此前缀）
axios.defaults.baseURL = '/api'


Vue.config.productionTip = false

Vue.use(ElementUI,{size:'small'});

/**
 * @name:
 * @description: 路由导航全局前置守卫,类似于后端的过滤器(https://router.vuejs.org/zh/guide/advanced/navigation-guards.html#%E5%85%A8%E5%B1%80%E5%89%8D%E7%BD%AE%E5%AE%88%E5%8D%AB)
 * @author: 皮蛋布丁
 * @date: 2021-05-16 16:05:18
 */
router.beforeEach((to, from, next) => {
  //初始化菜单数据
  //if(login页面)
  if (to.path == '/') {
    next();
  } else {
    //是否登录
    if (window.sessionStorage.getItem("user")) {
      initMenu(router,store);
      next();
    }else {
      next('/?redirect=' + to.path);
    }
  }
})

// export default { //后端地址
//   url: "/api"
// }



new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
